<template>
  <div class="todoFooter">
    <div class="todoFooterLeft">
      <el-checkbox
        size="large"
        v-model="isTotalDone"
        @change="TotalChange(isTotalDone)"
      />
      <span> 已完成{{ doneTotal }} /全部{{ Tatal }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { toNumber } from "lodash";
import { computed, PropType, ref, onMounted } from "vue";
type todo = {
  id: string;
  title: string;
  done: boolean;
};
// handleClick(event) {
//         // 点击后鼠标移开恢复按钮默认样式(如果按钮没有加icon图标的话，target.nodeName == "I"可以去掉)
//         let target = event.target;
//         if(target.nodeName == "I" || target.nodeName == "SPAN"){
//             target = event.target.parentNode;
//         }
//         target.blur();
//         //进行其他操作
//         ....
// }

interface props {
  todos: todo[];
  appTotalchange:Function
}


//test
const props = defineProps<props>();
let doneTotal = computed(() => {
  let i = 0;
  props.todos.forEach((todo) => {
    if (todo.done) i++;
  });
  return i;
});
let Tatal = computed(() => {
  let i = 0;
  i = props.todos.length;
  return i;
});
// let isTotalDone = ref(true);
let isTotalDone = computed(() => {
  if (doneTotal.value == Tatal.value) {
    return true;
  } else {
    return false;
  }
});

function TotalChange(isTotalDone: boolean) {
  props.appTotalchange(isTotalDone);
}
</script>

<style scoped>
.todoFooter {
  width: 535px;
  margin: 20px auto 0;
  display: flex;
  align-items: center;
  padding-left: 20px;
  justify-content: space-between;
  box-shadow: -2px 6px 11px rgb(0 0 0 / 14%);
}
</style>
